package com.arvato.admin01.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author xu yuanjun
 * @data 2020/3/29 13:30
 */
@RestController
@RequestMapping("/api")
public class AdminController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @RequestMapping("/getUsers")
    public List<Map<String, Object>> getDbType(){
        String sql = "select * from t_users";
        List<Map<String, Object>> list =  jdbcTemplate.queryForList(sql);
        for (Map<String, Object> map : list) {
            Set<Map.Entry<String, Object>> entries = map.entrySet( );
            if(entries != null) {
                Iterator<Map.Entry<String, Object>> iterator = entries.iterator( );
                while(iterator.hasNext( )) {
                    Map.Entry<String, Object> entry =(Map.Entry<String, Object>) iterator.next( );
                    Object key = entry.getKey( );
                    Object value = entry.getValue();
                    System.out.println(key+":"+value);
                }
            }
        }
        return list;
    }

    public static void main(String[] args) {

        int[] arr = new int[] {1,5,7,0,6,8,4,9,3};
        int[] index = new int[] {0, 1, 3, 7, 8, 6, 7, 5, 7, 4, 1};
        String tel = "";
        for (int i : index){
            tel += arr[i];
        }
        System.out.println("联系方式: "+tel);
    }
}
